/** 
 * Project Name:tinysql 
 * File Name:OracleSqlTypeConverter.java 
 * Package Name:com.wdy.golden.tinysql.extend 
 * Date:2021年4月7日下午8:22:40 
 * 
*/  
package com.wdy.golden.tinysql.extend;


import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URL;
import java.sql.Date;
import java.sql.SQLData;
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.ZonedDateTime;

import oracle.jdbc.LogicalTransactionId;
import oracle.jdbc.OracleTypes;
import oracle.jdbc.internal.ObjectData;
import oracle.sql.ARRAY;
import oracle.sql.BFILE;
import oracle.sql.BINARY_DOUBLE;
import oracle.sql.BINARY_FLOAT;
import oracle.sql.BLOB;
import oracle.sql.CHAR;
import oracle.sql.CLOB;
import oracle.sql.DATE;
import oracle.sql.Datum;
import oracle.sql.INTERVALDS;
import oracle.sql.INTERVALYM;
import oracle.sql.NUMBER;
import oracle.sql.OPAQUE;
import oracle.sql.RAW;
import oracle.sql.REF;
import oracle.sql.ROWID;
import oracle.sql.STRUCT;
import oracle.sql.TIMESTAMP;
import oracle.sql.TIMESTAMPLTZ;
import oracle.sql.TIMESTAMPTZ;

/** 
 * from: oracle.jdbc.driver.OraclePreparedStatement.sqlTypeForObject(Object var1)
 * ClassName:OracleSqlTypeConverter <br/> 
 * Function: TODO ADD FUNCTION. <br/> 
 * Reason:   TODO ADD REASON. <br/> 
 * Date:     2021年4月7日 下午8:22:40 <br/> 
 * @author   DongYe_Wu 
 * @version
 * @see       
 */
public class OracleSqlTypeConverter implements SqlTypeConverter {
	@Override
	public int getJdbcTypeByObject(Object var1) {
		return getJdbcTypeByObject(var1, false);
	}
	
	@Override
	public int getJdbcTypeByObject(Object var1, boolean fixedString) {
		if (var1 == null) {
			return 0;
		} else {
			if (!(var1 instanceof Datum)) {
				if (var1 instanceof String) {
					return fixedString ? OracleTypes.FIXED_CHAR : OracleTypes.VARCHAR;
				}

				if (var1 instanceof BigDecimal) {
					return OracleTypes.NUMERIC;
				}

				if (var1 instanceof BigInteger) {
					return OracleTypes.NUMBER;
				}

				if (var1 instanceof Boolean) {
					return OracleTypes.BIT;
				}

				if (var1 instanceof Integer) {
					return OracleTypes.INTEGER;
				}

				if (var1 instanceof Long) {
					return OracleTypes.BIGINT;
				}

				if (var1 instanceof Float) {
					return OracleTypes.REAL;
				}

				if (var1 instanceof Double) {
					return OracleTypes.DOUBLE;
				}

				if (var1 instanceof byte[]) {
					return OracleTypes.VARBINARY;
				}

				if (var1 instanceof Short) {
					return OracleTypes.SMALLINT;
				}

				if (var1 instanceof Byte) {
					return OracleTypes.TINYINT;
				}

				if (var1 instanceof Date) {
					return OracleTypes.DATE;
				}

				if (var1 instanceof Time) {
					return OracleTypes.TIME;
				}

				if (var1 instanceof Timestamp) {
					return OracleTypes.TIMESTAMP;
				}

				if (var1 instanceof SQLData) {
					return OracleTypes.STRUCT;
				}

				if (var1 instanceof ObjectData) {
					return OracleTypes.STRUCT;
				}

				if (var1 instanceof URL) {
					return fixedString ? OracleTypes.FIXED_CHAR : OracleTypes.VARCHAR;
				}

				if (var1 instanceof LogicalTransactionId) {
					return OracleTypes.BINARY;
				}

				if (var1 instanceof LocalDate) {
					return OracleTypes.TIMESTAMP;
				}

				if (var1 instanceof LocalTime) {
					return OracleTypes.TIMESTAMP;
				}

				if (var1 instanceof LocalDateTime) {
					return OracleTypes.TIMESTAMP;
				}

				if (var1 instanceof ZonedDateTime) {
					return OracleTypes.TIMESTAMPTZ;
				}

				if (var1 instanceof OffsetDateTime) {
					return OracleTypes.TIMESTAMPTZ;
				}

				if (var1 instanceof OffsetTime) {
					return OracleTypes.TIMESTAMPTZ;
				}

				if (var1 instanceof Duration) {
					return OracleTypes.INTERVALDS;
				}

				if (var1 instanceof Period) {
					return OracleTypes.INTERVALYM;
				}
			} else {
				if (var1 instanceof BINARY_FLOAT) {
					return OracleTypes.BINARY_FLOAT;
				}

				if (var1 instanceof BINARY_DOUBLE) {
					return OracleTypes.BINARY_DOUBLE;
				}

				if (var1 instanceof BLOB || var1 instanceof oracle.jdbc.driver.OracleBlob) {
					return OracleTypes.BLOB;
				}

				if (var1 instanceof CLOB || var1 instanceof oracle.jdbc.driver.OracleClob) {
					return OracleTypes.CLOB;
				}

				if (var1 instanceof BFILE || var1 instanceof oracle.jdbc.driver.OracleBfile) {
					return OracleTypes.BFILE;
				}

				if (var1 instanceof ROWID) {
					return OracleTypes.ROWID;
				}

				if (var1 instanceof NUMBER) {
					return OracleTypes.NUMBER;
				}

				if (var1 instanceof DATE) {
					return OracleTypes.DATE;
				}

				if (var1 instanceof TIMESTAMP) {
					return OracleTypes.TIMESTAMP;
				}

				if (var1 instanceof TIMESTAMPTZ) {
					return OracleTypes.TIMESTAMPTZ;
				}

				if (var1 instanceof TIMESTAMPLTZ) {
					return OracleTypes.TIMESTAMPLTZ;
				}

				if (var1 instanceof REF) {
					return OracleTypes.REF;
				}

				if (var1 instanceof CHAR) {
					return OracleTypes.CHAR;
				}

				if (var1 instanceof RAW) {
					return OracleTypes.RAW;
				}

				if (var1 instanceof ARRAY) {
					return OracleTypes.ARRAY;
				}

				if (var1 instanceof STRUCT) {
					return OracleTypes.STRUCT;
				}

				if (var1 instanceof OPAQUE) {
					return OracleTypes.OPAQUE;
				}

				if (var1 instanceof INTERVALYM) {
					return OracleTypes.INTERVALYM;
				}

				if (var1 instanceof INTERVALDS) {
					return OracleTypes.INTERVALDS;
				}

				if (var1 instanceof SQLXML) {
					return OracleTypes.SQLXML;
				}
			}

			return OracleTypes.OTHER;
		}
	}

}
